﻿using System.Collections;
using UnityEngine;

public class BaoxiangUp : MonoBehaviour
{
    public float amplitude;// 浮动的幅度
    public float frequency; // 浮动的频率

    private Vector3 originalPosition;

    void Start()
    {
        amplitude = 15f;
        frequency = 5f;
        originalPosition = transform.position; // 记录初始位置
    }

    void Update()
    {
        // 使用 Mathf.Sin 函数来计算物体的上下浮动
        float offset = Mathf.Sin(Time.time * frequency) * amplitude;
        transform.position = new Vector3(originalPosition.x, originalPosition.y + offset, originalPosition.z);
    }
}
